package com.buka.communicate.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.text.Html;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.buka.communicate.R;
import com.buka.communicate.adapter.WalletAdapter;
import com.jcodecraeer.xrecyclerview.ProgressStyle;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import net.neiquan.applibrary.base.BaseActivity;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/11/14 0014.
 */

public class WalletActivity extends BaseActivity {
    @InjectView(R.id.back_img)
    ImageView backImg;
    @InjectView(R.id.back_tv)
    TextView backTv;
    @InjectView(R.id.ly_back)
    LinearLayout lyBack;
    @InjectView(R.id.title_tv)
    TextView titleTv;
    @InjectView(R.id.next_tv)
    TextView nextTv;
    @InjectView(R.id.next_img)
    ImageView nextImg;
    @InjectView(R.id.searh_next_img)
    ImageView searhNextImg;
    @InjectView(R.id.head_view)
    RelativeLayout headView;
    @InjectView(R.id.coinRemain)
    TextView coinRemain;
    @InjectView(R.id.coinFirst)
    ImageView coinFirst;
    @InjectView(R.id.mRecylerView)
    XRecyclerView mRecylerView;
    @InjectView(R.id.troubleHint)
    TextView troubleHint;
    @InjectView(R.id.aliPayChosen)
    ImageView aliPayChosen;
    @InjectView(R.id.aliPayFL)
    FrameLayout aliPayFL;
    @InjectView(R.id.wxPayChosen)
    ImageView wxPayChosen;
    @InjectView(R.id.wxPayFL)
    FrameLayout wxPayFL;

    @Override
    public int getRootViewId() {
        return R.layout.activity_wallet;
    }

    @Override
    public void setViews() {
        setTitleTv("钱包");
        setNextTv("账单");
        Spanned spanned = Html.fromHtml("充值如遇到问题请<font color='#00ffff'><u>联系客服</u></font>");
        troubleHint.setText(spanned);
        setNextOnClick(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(WalletActivity.this,BillActivity.class));
            }
        });
        initRecylerView();
    }

    private void initRecylerView() {
        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2,
                StaggeredGridLayoutManager.VERTICAL);
        layoutManager.setOrientation(StaggeredGridLayoutManager.VERTICAL);
        mRecylerView.setLayoutManager(layoutManager);
        mRecylerView.setLoadingMoreEnabled(false);
        mRecylerView.setPullRefreshEnabled(false);
        mRecylerView.hideFootView();
        mRecylerView.setAdapter(new WalletAdapter(this, null));
        View footView = LayoutInflater.from(this).inflate(R.layout.layout_coin_head, null);
        final LinearLayout coinHeadLL = (LinearLayout) footView.findViewById(R.id.coinHeadLL);
        coinHeadLL.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                coinHeadLL.setBackground(getResources().getDrawable(R.drawable.shape_solid_app_corlor));
            }
        });
        mRecylerView.addFootView(footView);
    }

    @Override
    public void initData() {

    }

    @OnClick({R.id.troubleHint, R.id.aliPayFL, R.id.wxPayFL})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.troubleHint:

                break;
            case R.id.aliPayFL:
                changePayBg(true);
                break;
            case R.id.wxPayFL:
                changePayBg(false);
                break;
        }
    }

    private void changePayBg(boolean flag) {
        aliPayFL.setBackground(getResources().getDrawable(R.drawable.shape_cornor_white));
        aliPayChosen.setVisibility(View.GONE);
        wxPayFL.setBackground(getResources().getDrawable(R.drawable.shape_cornor_white));
        wxPayChosen.setVisibility(View.GONE);
        if (flag) {
            aliPayFL.setBackground(getResources().getDrawable(R.drawable.shape_cornor_line));
            aliPayChosen.setVisibility(View.VISIBLE);
        } else {
            wxPayFL.setBackground(getResources().getDrawable(R.drawable.shape_cornor_line));
            wxPayChosen.setVisibility(View.VISIBLE);
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.inject(this);
    }
}
